package ch.epfl.lara.matcheck;

import scala.util.parsing.input.Position


/** This class provides functionality for printing error messages.
*/
object Report {

 /** Number of errors.
  */
 private var errors: Int = 0;
 
 /** Number of warnings
 */
 private var warnings: Int = 0 

 private val warningMsg: String = "*** Warning: "
   
 def debug(message: String) {
   if (Config.DEBUG) println(message)
 }
 
 def debug(position: Position, message: String) {
   if (Config.DEBUG) println(position, message)
 }  
   
 /** Prints out an error message.
  */
 def error(message: String) {
   errors += 1;
   println(message);
 }

 /** Prints out an error message.
  */
 def error(position: Position, message: String) {
   errors += 1;
   println(string(position) + message)
 }
 
 def warning(message: String) {
   warnings += 1
   if (Config.WARNINGS || 
       Config.DEBUG) 
     println(warningMsg + message)
 }
 
 def warning(position: Position, message: String) {
   warnings += 1
   if (Config.WARNINGS || 
       Config.DEBUG) 
     println(position, warningMsg + message)
 }

 /** Prints out an error message and stops the program execution.
  */
 def fail(message: String) {
   error(message);
   System.exit(-1);
 }

 /** Prints out an error message and stops the program execution.
  */
 def fail(position: Position, message: String) {
   error(position, message);
   System.exit(-1);
 }

 /** Prints out an error message and stops the program execution.
  *  The prompt is clean in the sense that in-between two nl. 
  */
 def cleanFail(message: String) {
   fail("\n"+message+"\n")   
 }

 
 def verbose(message: String) {
   if(Config.VERBOSE || 
      Config.DEBUG)
     println(message)
 }
 
 def verbose(position: Position) {
   if(Config.VERBOSE || 
      Config.DEBUG) 
     println(string(position))
 }
 
 def verbose(position: Position, message: String) {
   if(Config.VERBOSE || 
      Config.DEBUG) {
     verbose(position)
     println(message)
   }
 }
 
 def print(message: String) {
   Console.out.print(message)
 }
 
 def println(message: String) {
   Console.out.println(message)
 }
 
 def println(position: Position) { 
   Console.out.println(string(position))
 }
 
 def println(pos: Position, message: String) {
   println(string(pos) + message)
 }
 
   
 private def string(position: Position): String = "@ line " + position.line + ": " 
 
}
